import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(HomeState state, Dispatch dispatch, ViewService viewService) {
  var showBar =
      state.tabIndex == 4 || (state.tabIndex == 0 && GlobalState.isTeacher);
  return Scaffold(
    appBar: showBar
        ? null
        : AppBar(
            centerTitle: true,
            elevation: 2.0,
            backgroundColor: Colors.white,
            title: Text(
              state.tabData[state.tabIndex]['title'],
              style: TextStyle(color: Colors.black54, fontSize: 18),
            ),
          ),
    body: viewService.buildComponent(state.tabData[state.tabIndex]['bodyName']),
    bottomNavigationBar: new BottomNavigationBar(
      iconSize: 24.0,
      items: state.myTabs,
      selectedItemColor: Colors.blue,
      //设置显示的模式
      type: BottomNavigationBarType.fixed,
      //设置当前的索引
      currentIndex: state.tabIndex,
      //tabBottom的点击监听
      onTap: (index) => dispatch(HomeActionCreator.onChangeTab(index)),
    ),
    floatingActionButton: GlobalState.isTeacher
        ? FloatingActionButton(
            backgroundColor: Colors.blue,
            foregroundColor: Colors.white,
            child: const Icon(Icons.edit),
            onPressed: () => dispatch(HomeActionCreator.onChangeTab(2)),
          )
        : null,
    floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  );
}
